#include <cstdio>
#include <cassert>
#include <algorithm>
using namespace std;
int read(){
	char c=getchar();int x=0;
	while(c<48||c>57) c=getchar();
	do x=x*10+(c^48),c=getchar();
	while(c>=48&&c<=57);
	return x;
}
const int N=1000003;
int n,rk;
int r1[N],r2[N];
int p[N],q[N],f[N];
int mn[N],id[N];
int rt(int x){
	if(f[x]==x) return x;
	return f[x]=rt(f[x]);
}
inline void eq(int x,int y){
	x=q[x];y=q[y];
	if(x>y) swap(x,y);
	while(rt(x)<y) f[rt(x)]=rt(x)+1;
}
inline bool neq(int x,int y){
	if(x>y) swap(x,y);
	x=id[rt(x)];y=id[rt(y)];
	if(x==y) return 1;
	if(mn[x]>y) mn[x]=y;
	return 0;
}
char c[N];
bool vis[N];
void solve(){
	n=read();rk=0;
	for(int i=1;i<=n;++i) p[i]=read()+1;
	for(int i=1;i<=n;++i) q[p[i]]=i,f[i]=i,vis[i]=0;
	q[n+1]=0;
	for(int i=1;i<n;++i) r1[i]=read()>>1,r2[i]=read()>>1;
	r1[n]=read()>>1;
	for(int i=1;i<=n;++i){
		if(vis[p[i]]){puts("-1");return;}
		vis[p[i]]=1;
	}
	for(int i=1;i<=n;++i) if(i+r1[i]>n||i-r1[i]<=0){puts("-1");return;}
	for(int i=1;i<n;++i) if(i+r2[i]>n||i-r2[i]+1<=0){puts("-1");return;}
	for(int i=1,mx=0,pos=0;i<=n;++i){
		int r=0;
		if(i<mx) r=min(r1[2*pos-i],mx-i);
		while(r<r1[i]) ++r,eq(i-r,i+r);
		if(i+r>mx) mx=i+r,pos=i;
	}
	for(int i=0,mx=0,pos=0;i<n;++i){
		int r=0;
		if(i<mx) r=min(r2[2*pos-i],mx-i);
		while(r<r2[i]) ++r,eq(i-r+1,i+r);
		if(i+r>mx) mx=i+r,pos=i;
	}
	for(int i=1;i<=n;++i) if(f[i]==i) id[i]=++rk;
	for(int i=1;i<=rk;++i) mn[i]=rk+1;
	for(int i=1;i<n;++i) if(q[p[i]+1]>q[p[i+1]+1]) if(neq(i,i+1)){puts("-1");return;}
	for(int i=1;i<=n;++i)
		if(i-r1[i]-1>0&&i+r1[i]+1<=n) if(neq(q[i-r1[i]-1],q[i+r1[i]+1])){puts("-1");return;}
	for(int i=1;i<n;++i)
		if(i-r2[i]>0&&i+r2[i]+1<=n) if(neq(q[i-r2[i]],q[i+r2[i]+1])){puts("-1");return;}
	int lim=mn[1];
	c[1]='a';
	for(int i=2;i<=rk;++i){
		c[i]=c[i-1];
		if(i==lim){
			lim=rk+1;
			if(c[i]=='z'){puts("-1");return;}
			++c[i];
		}
		if(lim>mn[i]) lim=mn[i];
	}
	for(int i=1;i<=n;++i) putchar(c[id[rt(q[i])]]);
	putchar('\n');
}
int main(){
	freopen("string.in","r",stdin);
	freopen("string.out","w",stdout);
	int tc=read();
	while(tc--) solve();
	return 0;
}
